/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "ComponentControl.h"
#include "ScriptComponent.h"
#include "ColliderComponent.h"
#include "RigidBodyComponent.h"

namespace PQBuilder
{
	ComponentControl::ComponentControl(PQEngine::Component* component,QWidget *parent)
		: WidgetBase(parent),_component(component)
	{
		this->setupUI();
	}

	ComponentControl::~ComponentControl()
	{
	}

	void ComponentControl::setupUI()
	{
		PQEngine::ObjectType type=_component->getObjectType();
		switch(type){
			case PQEngine::OBJECT_TYPE_COMPONENT_TRANSFORM:
				setupTransformUI((PQEngine::TransformComponent*)_component);
				break;
			case PQEngine::OBJECT_TYPE_COMPONENT_MESH:
				setupMeshUI((PQEngine::MeshComponent*)_component);
				break;
			case PQEngine::OBJECT_TYPE_COMPONENT_SCRIPT:
				setupScriptUI((PQEngine::ScriptComponent*)_component);
				break;
			case PQEngine::OBJECT_TYPE_COMPONENT_RIGIDBODY:
				setupRigidBodyUI((PQEngine::RigidBodyComponent*)_component);
				break;
			case PQEngine::OBJECT_TYPE_COMPONENT_BOX_COLLIDER:
				setupBoxColliderUI((PQEngine::BoxColliderComponent*)_component);
				break;
			case PQEngine::OBJECT_TYPE_COMPONENT_PLANE_COLLIDER:
				setupPlaneColliderUI((PQEngine::PlaneColliderComponent*)_component);
				break;
			case PQEngine::OBJECT_TYPE_COMPONENT_SPHERE_COLLIDER:
				setupSphereColliderUI((PQEngine::SphereColliderComponent*)_component);
				break;
			case PQEngine::OBJECT_TYPE_COMPONENT_TERRAIN:
				setupTerrainUI((PQEngine::TerrainComponent*)_component);
				break;
			default:
				break;
		}

	}

	void ComponentControl::setupTransformUI(PQEngine::Component* component)
	{
		_ui=new TransformUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Transform");
	}

	void ComponentControl::setupMeshUI(PQEngine::Component* component)
	{
		_ui=new MeshUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Mesh Entity");
	}

	void ComponentControl::setupScriptUI(PQEngine::Component* component)
	{
		_ui=new ScriptUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Script");
	}

	void ComponentControl::setupRigidBodyUI(PQEngine::Component* component)
	{
		_ui=new RigidBodyUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Rigid Body");
	}

	void ComponentControl::setupBoxColliderUI(PQEngine::Component* component)
	{
		_ui=new BoxColliderUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Box Collider");
	}

	void ComponentControl::setupPlaneColliderUI(PQEngine::Component* component)
	{
		_ui=new PlaneColliderUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Plane Collider");
	}

	void ComponentControl::setupSphereColliderUI(PQEngine::Component* component)
	{
		_ui=new SphereColliderUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Sphere Collider");
	}

	void ComponentControl::setupTerrainUI(PQEngine::Component* component)
	{
		_ui=new TerrainUI();
		_ui->setupUI(this,component);
		_text=QObject::tr("Terrain");
	}


	void TransformUI::setupUI(QWidget* widget, PQEngine::Component* cpnt)
	{
		if(!cpnt||cpnt->getObjectType()!=PQEngine::OBJECT_TYPE_COMPONENT_TRANSFORM){
			return;
		}

		PQEngine::TransformComponent* component=(PQEngine::TransformComponent*)cpnt;
		_control=new TransformControl(widget,component);
		QVBoxLayout* box=new QVBoxLayout();
		box->addWidget(_control);
		box->setMargin(0);
		widget->setLayout(box);
		widget->setMaximumHeight(_control->getControlHeight());
	}

	void TerrainUI::setupUI(QWidget* widget, PQEngine::Component* cpnt)
	{
		if(!cpnt||cpnt->getObjectType()!=PQEngine::OBJECT_TYPE_COMPONENT_TERRAIN){
			return;
		}

		PQEngine::TerrainComponent* component=(PQEngine::TerrainComponent*)cpnt;
		_control=new TerrainControl(widget,component);
		QVBoxLayout* box=new QVBoxLayout();
		box->addWidget(_control);
		box->setMargin(0);
		widget->setLayout(box);
	}

}
